﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace PartitionsCodegen
{
    public partial class SettingsForm : Form
    {
        private MainForm mf;

        public SettingsForm(MainForm mf, int x, int y, int d_z, int d_xy)
        {
            this.mf = mf;
            InitializeComponent();

            textBoxXLimit.Text = ""+x;
            textBoxYLimit.Text = ""+y;
            textBoxZdwell.Text = "" + d_z;
            textBoxXYdwell.Text = "" + d_xy;
            
        }





        private int getXlimit() { return Int32.Parse(textBoxXLimit.Text); }
        private int getYlimit() { return Int32.Parse(textBoxYLimit.Text); }
        private int getZdwell() { return Int32.Parse(textBoxZdwell.Text); }
        private int getXYdwell() { return Int32.Parse(textBoxXYdwell.Text); }


        private string validateXlimit()
        {
            int ret;
            bool ok = Int32.TryParse(textBoxXLimit.Text, out ret);
            if (!ok) return "Ingrese número válido en Limite X\n";
            return "";
        }

        private string validateYlimit()
        {
            int ret;
            bool ok = Int32.TryParse(textBoxYLimit.Text, out ret);
            if (!ok) return "Ingrese número válido en Limite Y\n";
            return "";
        }
        private string validateZDwell()
        {
            int ret;
            bool ok = Int32.TryParse(textBoxZdwell.Text, out ret);
            if (!ok) return "Ingrese número válido en tiempo de espera entre profundidades\n";
            return "";
        }
        private string validateXYDwell()
        {
            int ret;
            bool ok = Int32.TryParse(textBoxXYdwell.Text, out ret);
            if (!ok) return "Ingrese número válido en tiempo de espera entre copias\n";
            return "";
        }



        private void errorAlert(string alert_msg)
        {
            DialogResult dlgRes = MessageBox.Show(alert_msg, "Error",
            MessageBoxButtons.OK,
            MessageBoxIcon.Error);
        }

        private void buttonAceptar_Click(object sender, EventArgs e)
        {

            string errors = validateXlimit() + validateYlimit() + validateZDwell() + validateXYDwell();

            if (errors.Length > 0) errorAlert(errors);
            else
            {
                mf.setBoardLimitX(getXlimit());
                mf.setBoardLimitY(getYlimit());
                mf.setDwellTimeZ(getZdwell());
                mf.setDwellTimeCopies(getXYdwell());
                this.Close();

            }

            
        }

        private void buttonCancelar_Click(object sender, EventArgs e)
        {
            this.Close();
        }






    }
}
